home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
gamesrc
/
rtanksrc
/
input.c
< prev
next >
Wrap
Text File
|
1989-02-09
|
3KB
|
136 lines
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <string.h>
#include <dtypes.h>
#include <conio.h>
#include <ctype.h>
#include <nkeybd.h>
#include "input.h"
#define BLOCK 22
static int x,y,l,maxlen;
static char b[80];
/*
* Function : void _add_char(int ch)
* Purpose : Append a character to buf
* Date : 10/06/1988 22:40:56
*/
void _add_char(int ch)
{
if (l<maxlen) {
b[l++]=ch;
b[l]=NULL;
gotoxy(x++,y); putch(ch);
} else putchar(7);
} /* void _add_char(int ch) */
/*
* Function : void _del_char(void)
* Purpose : Deletes the last character in the buffer
* Date : 10/06/1988 22:48:38
*/
void _del_char(void)
{
if (l>0) {
b[--l]=NULL;
gotoxy(--x,y); putch(BLOCK);
gotoxy(x,y);
} else putchar(7);
} /* void _del_char(void) */
/*
* Function : char *getline(int len, char *s)
* Purpose : Gets a LEN length string from keyboard and stores it in S.
* Date : 10/06/1988 20:06:03
*/
char *getline(int len, char *s)
{
int ox,oy,a;
BOOL first;
char ch;
x=ox=wherex(); y=oy=wherey();
l=0; maxlen=len;
first=TRUE;
gotoxy(x,y);
if (*s) cputs(s);
for (a=strlen(s); a<len; a++) putch(BLOCK);
gotoxy(ox,oy);
do {
while (!kbhit())
;
ch=getkey();
if (isprint(ch)) {
if (first) {
gotoxy(ox,oy);
for (a=0; a<len; a++) putch(BLOCK);
gotoxy(ox,oy);
first=FALSE;
}
_add_char(ch);
} else {
switch(ch) {
case CR : if (first) {
strcpy(b,s);
x+=strlen(s);
}
if (strlen(b) < len) {
gotoxy(x,y);
for (a=strlen(b); a<len; a++)
putch(' ');
}
gotoxy(ox,oy);
b[len]=NULL;
break;
case BS : _del_char();
if (l==0) {
gotoxy(ox,oy);
if (*s) cputs(s);
for (a=strlen(s); a<len; a++) putch(BLOCK);
gotoxy(ox,oy);
first=TRUE;
}
break;
default : putchar(7); break;
}
} /* if not printable character */
} while (ch!=CR);
strcpy(s,b);
return(s);
} /* char *getline(int len, char *s) */
/*
* Function : float get_float(int l, char *s)
* Purpose : Returns a floating point number returned from keyboard
* Date : 10/06/1988 20:04:11
*/
float get_float(int l, char *s)
{
return(atof(getline(l,s)));
} /* float get_float(int l, char *s) */
/*
* Function : int get_int(int l, char *s)
* Purpose : Returns an integer from user keyboard input
* Date : 10/06/1988 23:24:39
*/
int get_int(int l, char *s)
{
return(atoi(getline(l,s)));
} /* int get_int(int l, char *s) */